Computer Science Notes: Pointer Algebra & Alignment
Pointer Arithmetic Multipliers
Adding an integer to a pointer instructs the underlying ALU to advance the base address by K * sizeof(Type) bytes, ensuring flawless traversal across contiguous physical storage arrays.
===================================================================================
POINTER ARITHMETIC MULTIPLICATION MATRIX
===================================================================================
[ Base Address: 0x1000 ] (int *p)
β
βββΊ p + 1 ββ> 0x1000 + (1 * 4 bytes) ββ> 0x1004
βββΊ p + 2 ββ> 0x1000 + (2 * 4 bytes) ββ> 0x1008
βββΊ p + 3 ββ> 0x1000 + (3 * 4 bytes) ββ> 0x100C
===================================================================================
Struct Padding & Data Alignment
Modern microprocessors fetch memory in uniform 8-byte chunks. The compiler injects uninitialized Padding Bytes to ensure natural word alignment and prevent hardware clock cycle penalties.
Asymptotic Boundaries: Stack vs. Buffer Overflow
Stack Overflow is triggered by unbounded recursion exhausting stack frames, whereas Buffer Overflow corrupts adjacent memory buffers and overwrites base function return address pointers.